package com.mmy.dao.plane;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.plane.TPlanePlan;

public interface TPlanePlanRepository extends JpaRepository<TPlanePlan, Integer> {
	/**
	 * 获取计划单最大值
	 * 
	 * @return 返回值说明 最大计划单编码
	 * @author 创建人 dingxd
	 * @date 创建日期 2020.11.16
	 */
	@Query(value = "SELECT MAX(iPlanID) FROM tPlanePlan WHERE LEFT(iPlanID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxPlanID();

	/**
	 * 创建
	 *
	 * @author 创建人 hanxl
	 * @param strOrderTel
	 * @param strOrderName
	 * @date 创建日期 2021.03.17
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tPlanePlan(iPlanID, cStandard, iPlaneID, iZoneOutID, iAirportOutID, iZoneInID, iAirportInID, dStartDate, dEndDate, fLong, fFloor, fPeer, fPrice, iNumber, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:planID, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("planID") int planID);

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tPlanePlan where tPlanePlan.iPlanID in (:lstPlanID)", nativeQuery = true)
	void delPlanePlan(@Param("lstPlanID") List<Integer> lstPlanID);

	/**
	 * 根据ID查询
	 *
	 * @author 创建人 hanxl
	 * @param strOrderTel
	 * @param strOrderName
	 * @date 创建日期 2021.03.17
	 */
	@Query(value = "select *  from tPlanePlan where iPlanID = :iPlanID", nativeQuery = true)
	TPlanePlan findByPlanID(@Param("iPlanID") int iPlanID);

}
